package com.sysd.server.code;

import com.alibaba.fastjson2.JSONObject;
import com.sysd.bean.BaseMessage;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;

import java.util.List;

/**
 * @description:
 * @author: bsh
 * @date: 2025/6/5 10:31
 */
public class MessageEncode extends MessageToMessageEncoder<BaseMessage> {

    /**
     * @param channelHandlerContext 上下文
     * @param message               消息
     * @param list                  list
     * @throws Exception 异常
     */
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, BaseMessage message, List<Object> list) throws Exception {
        list.add(new TextWebSocketFrame(JSONObject.toJSONString(message)));
    }
}
